home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / diskutil / unixflop.lzh / RAW2TAR.C < prev    next >
C/C++ Source or Header  |  1987-04-22  |  2KB  |  92 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <osbind.h>
  4.  
  5. int size = 0;
  6. int fd, s = 0, s_max = 512 * 9 * 2 * 80;
  7. int track = 0, side = 0;
  8. int block=0;
  9. char buf[5120];
  10. long total_size = 0;
  11.  
  12. int
  13. main(argc,argv)
  14. int argc;
  15. char *argv[];
  16. {
  17.     puts("Insert raw disk in drive A. Hit CR to create file D:\\A.TAR\n");
  18.     getchar();
  19.     fd = open("D:\\A.TAR", O_WRONLY | O_CREAT | O_BINARY);
  20.     if (!fd)
  21.         fatal_error("Cannot open file D:\\A.TAR\n");
  22.     for (;;) {
  23.         if(convert_track(1, 0)) break;
  24.     if(convert_track(0, 1)) break;
  25.     }
  26.     close(fd);
  27.     printf("%ld bytes written. Hit CR to exit.\n", total_size);
  28.     getchar();
  29.     return 0;
  30. }
  31.  
  32. convert_track(next_side, incr_track)
  33. int next_side, incr_track;
  34. {
  35.     char mess[80];
  36.  
  37.     if (Floprd(buf, 0L, 0, 1, track, side, 9)) {
  38.         sprintf(mess, "error reading track %d, side %d\n", track, side);
  39.         fatal_error(mess);
  40.     }
  41.     block = print_names(block, s, s +9 < s_max ? s+9 : s_max);
  42.     side = next_side; s += 9; track += incr_track;
  43.     if (s >= s_max) {
  44.        write_buf(s_max - (s - 9));
  45.         return 1;
  46.     } else {
  47.         write_buf(9);
  48.            return 0;
  49.     }
  50. }
  51.  
  52. write_buf(size)
  53. int size;
  54. {
  55.     int written_size = write(fd, buf, 512 * size);
  56.         if (written_size != 512 * size)
  57.             fatal_error("No more room left on drive D:!\n");
  58.         total_size += written_size;
  59. }
  60.  
  61. int print_names(block, s, s_end)
  62. int block, s, s_end;
  63. {
  64.     /* printf("Block %d, s = %d, s_end = %d\n", block,s,s_end); */
  65.     while (block >= s && block < s_end) {
  66.         if (buf[(block-s) * 512] == '\0') {
  67.         /* end of tape reached */
  68.             printf("End of file at block %d\n", block);
  69.             s_max = block;
  70.             block = -1;
  71.         } else {
  72.             long size;
  73.             sscanf(buf + (block-s) * 512 + 124, " %lo", &size);
  74.             printf("Block %d: %.100s %ld\n", block, buf + (block-s) * 512, size);
  75.             if (size)
  76.                 block = block + 2 + (int) ((size - 1)/ 512);
  77.             else
  78.                 block++;
  79.          }
  80.     }
  81.     return block;
  82. }
  83.  
  84. fatal_error(s)
  85. char *s;
  86. {
  87.     puts(s);
  88.     puts("\007Aborting... Press CR\n");
  89.     getchar();
  90.     exit(1);
  91. }
  92.